package com.tiennt.android.threeview;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.widget.Toast;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class MyMapOverlay extends ItemizedOverlay<OverlayItem> {

	private Context mContext;
	ArrayList<OverlayItem> mOverlayItems;

	public MyMapOverlay(Drawable defaultMarker) {
		super(boundCenterBottom(defaultMarker));
		populate();
		// TODO Auto-generated constructor stub
	}

	public MyMapOverlay(Context context, Drawable defaultMaker) {
		super(boundCenterBottom(defaultMaker));
		mContext = context;
		mOverlayItems = new ArrayList<OverlayItem>();
		populate();
	}

	@Override
	protected OverlayItem createItem(int i) {
		// TODO Auto-generated method stub
		return mOverlayItems.get(i);
	}

	@Override
	public int size() {
		// TODO Auto-generated method stub
		return mOverlayItems.size();
	}

	@Override
	protected boolean onTap(int index) {
		// TODO Auto-generated method stub
		GeoPoint geoPoint = mOverlayItems.get(index).getPoint();
		String content = "Location:\nLattitude: " + geoPoint.getLatitudeE6()
				/ 1E6 + "\nLongitude: " + geoPoint.getLongitudeE6() / 1E6;
		Toast.makeText(mContext, content, Toast.LENGTH_LONG).show();
		return true;

	}
	
	public void addOverlayItem(OverlayItem item){
		mOverlayItems.add(item);
		populate();
	}

}
